using System;
using System.Collections.Generic;

namespace PegasCompany.Data
{
	public partial class FileAttach : IComparable<FileAttach>
	{
		public void Save()
		{
			IsDeleted = false;
		    IsVisible = true;
			CreateDate = DateTime.Now;
			LastModifiedDate = DateTime.Now;

			Insert();
		}

		public void UpdateInstance()
		{
			LastModifiedDate = DateTime.Now;

			Update();
		}

		public void MarkAsDeleted()
		{
			IsDeleted = true;

			Update();
		}

		public static List<FileAttach> ListByTemplateId(int templateId)
		{
			List<FileAttach> attachList = Search(
				new FileAttach
					{
						TemplateId = templateId,
						IsDeleted = false
					});
			attachList.Sort();
			return attachList;
		}

		public static List<FileAttach> ListBySiteContentId(int siteContentId)
		{
			List<FileAttach> attachList = Search(
				new FileAttach
				{
					SiteContentId = siteContentId,
					IsDeleted = false
				});
			attachList.Sort();
			return attachList;
		}

		public int CompareTo(FileAttach other)
		{
			return DocumentName.CompareTo(other.DocumentName);
		}
	}
}

